package com.typy.www.tpay.ui.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.typy.www.tpay.R;
import com.typy.www.tpay.util.LocalDisplay;
import com.typy.www.tpay.util.Logutil;
import com.zhy.android.percent.support.PercentRelativeLayout;


/**
 * Created by jiajie on 2018/1/24.
 */

public class RedEnvelopeDialog extends Dialog {

    protected Context mContext;

    private View mView;
    private LinearLayout mLlContent;
    private PercentRelativeLayout mRlContent;
    private LinearLayout ll_save;
    private ImageView mIvDelete;
    private TextView mTvTip;

    private OnDismantlingListener listener;

    public RedEnvelopeDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);

        this.mContext = context;

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mView = inflater.inflate(R.layout.conten_redenveiope_dialog, null);
        mLlContent = (LinearLayout) mView.findViewById(R.id.ll_content);
        ll_save = (LinearLayout) mView.findViewById(R.id.ll_save);
        mRlContent = (PercentRelativeLayout) mView.findViewById(R.id.rl_root);
        mIvDelete = (ImageView) mView.findViewById(R.id.iv_delete);
        mTvTip = (TextView) mView.findViewById(R.id.tv_tip);

        //图片的宽高
        int picW = mIvDelete.getWidth();
        int picH = mIvDelete.getHeight();


        int h = LocalDisplay.SCREEN_HEIGHT_PIXELS;
        int w = LocalDisplay.SCREEN_WIDTH_PIXELS;
//        w = (w * 4) / 5;
//        h = (w * 1774) / 1346;

//        w = (w * 4) / 5;
//        h = (h * 3) / 5;
        this.addContentView(mView,
                new LinearLayout.LayoutParams(
                        w,
                        h));//设置大小
    }

    public OnDismantlingListener getListener() {
        return listener;
    }

    public void setListener(OnDismantlingListener listener) {
        this.listener = listener;
    }

    /**
     * @param id  红包ID
     * @param tip 提示语
     */
    public void updataView(final String id, String tip) {
        mIvDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener != null) {
                    listener.onDismantlingRespon(0);
                }
            }
        });
        mTvTip.setText(tip);
        mRlContent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener != null) {
                    listener.onDismantlingRespon(0);
                }
            }
        });
        ll_save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener != null) {
                    listener.onDismantlingRespon(1);
                }
            }
        });
    }

    /**
     * 拆红包
     */
    public interface OnDismantlingListener {
        public void onDismantlingRespon(int type);
    }
}
